package com.heer.gymnasium.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.heer.gymnasium.AppHelper;
import com.heer.gymnasium.activity.LoginActivity;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by heer on 16/6/1.
 */
public class BaseFragment extends Fragment {
    protected Context mContext;
    protected Unbinder unbinder;
    protected AppHelper mAppHelper;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mAppHelper = AppHelper.context();
        mContext = getActivity();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(setConvertView(), null);
        bindView(view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        init();
        initView();
        loadData();
    }

    protected int setConvertView() {
        return 0;
    }

    protected void init() {
    }

    protected void initView() {
    }

    protected void bindView(View view) {
        unbinder = ButterKnife.bind(this, view);
    }

    protected void loadData() {
        loadData(false);
    }

    protected void loadData(boolean loadmore) {
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    protected void toLogin(){
        Intent intent = new Intent(mContext, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
    }
}
